// 30min used
#include "kernel/types.h"
#include "user/user.h"

int main(int argc, char *argv[]) {
  int ping_fd[2], pong_fd[2];
  pipe(ping_fd);
  pipe(pong_fd);

  if (fork()) {
    /* parent */
    close(ping_fd[0]);
    close(pong_fd[1]);

    char buf;
    int status;

    write(ping_fd[1], "0", 1);
    read(pong_fd[0], &buf, 1);
    printf("%d: received pong\n", getpid());

    wait(&status);
    exit(0);

  } else {
    /* child */
    close(ping_fd[1]);
    close(pong_fd[0]);

    char buf;

    read(ping_fd[0], &buf, 1);
    printf("%d: received ping\n", getpid());
    write(pong_fd[1], "1", 1);

    exit(0);
  }
}
